/*
 * keys.h
 *
 *  Created on: 12.02.2012
 *      Author: Roma Jam
 */

#ifndef KEYS_H_
#define KEYS_H_


#define BTN_GPIO_PORT               GPIOA
#define BTN_CLK                     RCC_APB2Periph_GPIOA

#define BTN_1                       GPIO_Pin_12
#define BTN_2                       GPIO_Pin_11
#define BTN_3                       GPIO_Pin_8
#define BTN_a                       GPIO_Pin_7
#define BTN_b                       GPIO_Pin_1
#define BTN_c                       GPIO_Pin_0

#define Enable_first_line_buttns()  GPIO_SetBits(BTN_GPIO_PORT,BTN_a)
#define Enable_second_line_buttns() GPIO_SetBits(BTN_GPIO_PORT,BTN_b)
#define Enable_third_line_buttns()  GPIO_SetBits(BTN_GPIO_PORT,BTN_c)
#define Disable_first_line_buttns() GPIO_ResetBits(BTN_GPIO_PORT,BTN_a)
#define Disable_second_line_butts() GPIO_ResetBits(BTN_GPIO_PORT,BTN_b)
#define Disable_third_line_buttns() GPIO_ResetBits(BTN_GPIO_PORT,BTN_c)


#define BTN1_IS_PRESSED()           (GPIO_ReadInputDataBit(BTN_GPIO_PORT, BTN_1))
#define BTN2_IS_PRESSED()           (GPIO_ReadInputDataBit(BTN_GPIO_PORT, BTN_2))
#define BTN3_IS_PRESSED()           (GPIO_ReadInputDataBit(BTN_GPIO_PORT, BTN_3))

enum key_name_t {
    None, F1, F2, F3, Left, Up, Right, Stop, Down, Start, Error
};
extern key_name_t key_name;

class keys_t {
private:
public:
    void Init(void);
    void Task(void);
    void IO_Switch(uint16_t Pin1, uint16_t Pin2, uint16_t Pin3);
    key_name_t Check_Keypressed(uint8_t Check_value);
    void Event_Keypressed(key_name_t Value_of_Key);
};
extern keys_t KEYS;

struct keyspressed_t {
    bool key_is_press;
    bool key_was_pressed;
    uint8_t string_of_key;
    uint32_t timer;
};
extern keyspressed_t key;


#endif /* KEYS_H_ */
